package com.ruoyi.loginfo.controller;

import java.util.List;
import java.io.IOException;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.loginfo.domain.LogPerson;
import com.ruoyi.loginfo.service.ILogPersonService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 快递员Controller
 * 
 * @author ruoyi
 * @date 2023-10-15
 */
@RestController
@RequestMapping("/person")
public class LogPersonController extends BaseController
{
    @Autowired
    private ILogPersonService logPersonService;

    /**
     * 查询快递员列表
     */
    @RequiresPermissions("loginfo:person:list")
    @GetMapping("/list")
    public TableDataInfo list(LogPerson logPerson)
    {
        startPage();
        List<LogPerson> list = logPersonService.selectLogPersonList(logPerson);
        return getDataTable(list);
    }

    /**
     * 导出快递员列表
     */
    @RequiresPermissions("loginfo:person:export")
    @Log(title = "快递员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LogPerson logPerson)
    {
        List<LogPerson> list = logPersonService.selectLogPersonList(logPerson);
        ExcelUtil<LogPerson> util = new ExcelUtil<LogPerson>(LogPerson.class);
        util.exportExcel(response, list, "快递员数据");
    }

    /**
     * 获取快递员详细信息
     */
    @RequiresPermissions("loginfo:person:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(logPersonService.selectLogPersonById(id));
    }

    /**
     * 新增快递员
     */
    @RequiresPermissions("loginfo:person:add")
    @Log(title = "快递员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LogPerson logPerson)
    {
        Long userId = SecurityUtils.getUserId();
        System.out.println(userId);
        LogPerson logPerson1 = new LogPerson();
        //设置快递员的手机id
        logPerson1.setPhone(logPerson.getPhone());
        //设置快递员的手机号码
        logPerson1.setContactPhone(logPerson.getContactPhone());
        //设置快递员的姓名
        logPerson1.setName(logPerson.getName());
        //设置快递员注册的uuid
        logPerson1.setSystemUserId(userId);
        //设置快递员的状态
        logPerson1.setStatus(0);
        System.out.println("接收的数据是=");
        System.out.println(logPerson);
        return toAjax(logPersonService.insertLogPerson(logPerson1));
    }

    /**
     * 修改快递员
     */
    @RequiresPermissions("loginfo:person:edit")
    @Log(title = "快递员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LogPerson logPerson)
    {
        return toAjax(logPersonService.updateLogPerson(logPerson));
    }

    /**
     * 删除快递员
     */
    @RequiresPermissions("loginfo:person:remove")
    @Log(title = "快递员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(logPersonService.deleteLogPersonByIds(ids));
    }
}
